{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<style>
    .layui-laydate-header {
        display: none;
    }

    .layui-laydate-content > table > thead {
        display: none;
    }

    .laydate-day-prev {
        display: none;
    }

    .laydate-day-next {
        display: none;
    }

    .pl_btn {
        color: #4c9cfb !important;
        cursor: pointer;
    }
    .countBan{
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-content: center;
        justify-content: flex-end;
    }
    .count_item_show{
        display: flex;
        margin: 10px;
        align-content: center;
        align-items: center;
    }
</style>
<form class="layui-form p-4">
    <h3 class="pb-3">功能菜单/节点</h3>
    <table class="layui-table layui-table-form">
        <tr>
                        <td class="layui-td-gray">采购单位
                        </td>
                        <td>
                            <select name="salesUnitId" lay-search lay-filter="salesUnitId" disabled>
                                <option value="">无</option>
                                {volist name='saleUniList' id='sl'}
                                <option value="{$sl.id}"  {if isset($detail.salesUnitId)&&$detail.salesUnitId==$sl.id} selected {/if}>{$sl.title}</option>
                                {/volist}
                            </select>
                        </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">单号<font>*</font>
            </td>
            <td>
                <input type="text" name="orderNum" value="{$detail.orderNum|default=''}" lay-verify="required" readonly
                       autocomplete="off" placeholder="请输入名称"
                       class="layui-input disabled">
            </td>
            <td class="layui-td-gray">供应商<font>*</font>
            </td>
            <td>
                <select name="punterId" id="punterId" lay-search lay-filter="punterId">
                    <option value="">选择供应商</option>
                    {volist name='punterList' id='pl'}
                    <option value="{$pl.id}" {if isset($detail.punterId)&&$detail.punterId==$pl.id} selected {/if}>{$pl.name}</option>
                    {/volist}
                </select>
            </td>
            <td class="layui-td-gray">单据日期<font>*</font></td>
            <td>
                <input type="text" name="orderDate" id="orderDate" value="{$detail.orderDate|default=$orderDate}" lay-verify="required" readonly
                       autocomplete="off" placeholder="选择日期"
                       class="layui-input">
            </td>
        </tr>
        <tr>

            <!--            <td class="layui-td-gray">销售单位-->
            <!--            </td>-->
            <!--            <td>-->
            <!--                <select name="salesUnitId" lay-search lay-filter="salesUnitId">-->
            <!--                    <option value="">销售单位</option>-->
            <!--                    {volist name='saleUniList' id='sl'}-->
            <!--                    <option value="{$sl.id}"  {if isset($detail.salesUnitId)&&$detail.salesUnitId==$sl.id} selected {/if}>{$sl.title}</option>-->
            <!--                    {/volist}-->
            <!--                </select>-->
            <!--            </td>-->
            <!--            <td class="layui-td-gray-2">销售员<font>*</font>-->
            <!--            </td>-->
            <!--            <td>-->
            <!--                <select name="saleId" id="saleId">-->
            <!--                    <option value="">选择销售员</option>-->
            <!--                </select>-->
            <!--            </td>-->
            <td class="layui-td-gray-2">税率(%)
            </td>
            <td>
                <select name="tax" id="tax">

                    {if isset($detail.tax)}
                    {volist name='quoOrderTax' id='qt'}
                    <option value="{$qt}" {if $detail.tax==$qt} selected{/if}>{$qt}</option>
                    {/volist}
                    {else}
                    {volist name='quoOrderTax' id='qt'}
                    <option value="{$qt}" {if $qt ==13} selected{/if}>{$qt}</option>
                    {/volist}
                    {/if}

                </select>
            </td>
            <td class="layui-td-gray">打印模板</td>
            <td>
                <select name="printTemplate" >
                    {volist name='printTemplateList' id='ptl'}
                    <option value="{$ptl.id}" {if isset($detai.printTemplate)&&$detail.printTemplate ==$ptl.id} selected {/if}>{$ptl.name}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        <tr>

            <td class="layui-td-gray">联系人
            </td>
            <td>
                <select name="contactId" id="contactId" lay-filter="contactId" lay-search >
                    <option value="">供应商联系人</option>
                </select>
            </td>
            <td class="layui-td-gray-2">联系电话
            </td>
            <td>
                <input type="text" name="contactPhone" value="{$detail.contactPhone|default=''}"  readonly class="layui-input layui-disabled" placeholder="选择联系人">
                <input type="hidden" name="contactName" value="{$detail.contactName|default=''}">
            </td>
            <td class="layui-td-gray">采购人</td>
            <td>{$detail.saleName|default=''}</td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">备注
            </td>
            <td>
                <input type="text" name="htRemark" value="{$detail.htRemark|default=''}"  readonly  class="layui-input " placeholder="备注">

            </td>
        </tr>
        <!--        <tr>-->

        <!--            <td class="layui-td-gray">收货人-->
        <!--            </td>-->
        <!--            <td>-->
        <!--                <select name="saveId" id="saveId" lay-search lay-filter="saveId">-->
        <!--                    <option value="">请选择</option>-->
        <!--                </select>-->
        <!--            </td>-->
        <!--            <td class="layui-td-gray-2">收货人电话-->

        <!--            </td>-->
        <!--            <td> <input type="text" name="savePhone" value="{$detail.savePhone|default=''}" lay-verify="required" readonly class="layui-input layui-disabled" placeholder="选择收货人">-->
        <!--                <input type="hidden" name="saveName" value="{$detail.saveName|default=''}">-->
        <!--            </td>-->
        <!--            <td class="layui-td-gray-2">收货人地址-->
        <!--            </td>-->
        <!--            <td>-->
        <!--                <input type="text" name="saveAdd" value="{$detail.saveAdd|default=''}" lay-verify="required" readonly class="layui-input layui-disabled" placeholder="选择收货人">-->

        <!--            </td>-->
        <!--        </tr>-->
        <tr>
            <td colspan="6"><h4>明细</h4></td>
        </tr>
        <tr>

            <td colspan="6">
                {if !isset($detail.status)||$detail.status==1}
<!--                <a href="javascript:" data-url="{:url('addMx')}" data-width="1000"-->
<!--                   class="layui-btn layui-btn-primary " onclick="getBjd()">关联销售合同</a>-->
<!--                <a href="javascript:" data-url="{:url('addPro')}" data-width="1000"-->
<!--                   class="layui-btn layui-btn-primary " onclick="getPro()">选择产品</a>-->
<!--                {/if}-->
                <input type="hidden" name="isTax" title="含税" id="isTax" {if isset($detail.isTax)&&$detail.isTax==1} checked {/if} value="1">
                <table class="layui-table tableMany">
                    <thead>
                    <tr>
                        <td>序号</td>
                        <!--                        <td>物料编码</td>-->
                        <td>品牌</td>
                        <td>品名</td>
                        <td>型号</td>
                        <td>订货号</td>
                        <td>单位</td>
                        <td>采购数量</td>
                        <td>含税单价</td>
                        <td>未税单价</td>
                        <td>含税小计</td>
                        <!--                        <td>未税总额</td>-->
                        <!--                        <td>税额</td>-->
                        <td>备注</td>
                        <td>关联销售合同</td>
                        <td>销售数量</td>
                        <td>未采购数量</td>
                        <td>货期</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody id="mxTbdy">
                    {if $mxList}
                    {volist name='mxList' id='mxl' key='mkey'}
                    <tr>
                        <td>
                            <span class="xuhao">{$mkey}</span>
                            <input type="hidden" name="mx[mxid][]" value="{$mxl.id}">
                            <input type="hidden" class="mx_mdId"  name="mx[mdId][]" value="{$mxl.mdId}">
                            <input type="hidden" class="layui-input taxMoney" value="{$mxl.taxMoney}" readonly name="mx[taxMoney][]">
                            <input type="hidden" class="layui-input noTaxMoney" value="{$mxl.noTaxMoney}"  name="mx[noTaxMoney][]">
                            <input type="hidden" name="mx[saleContractDetailId][]" class="mx_saleContractDetailId" value="{$mxl.saleContractDetailId}">
                        </td>
                        <!--                        <td>{$mxl.bar_code}</td>-->
                        <td>{$mxl.brand}</td>
                        <td>{$mxl.mdName}</td>
                        <td>{$mxl.specs}</td>
                        <td>{$mxl.buyCode}</td>
                        <td>{$mxl.unit}</td>
                        <td><input type="text" name="mx[bjNum][]" value="{$mxl.bjNum}" class="layui-input bjNum" onblur="getMoneys(this)"
                                   lay-verify="required" oninput="digitalFiltering(this,4)"></td>
                        <td><input type="text" name="mx[bjPrice][]" value="{$mxl.bjPrice}" class="layui-input bjPrice" onblur="getMoneys(this)"
                                   lay-verify="required" oninput="digitalFiltering(this,4)"></td>
                        <td><input type="text" class="layui-input noTaxPrice" value="{$mxl.noTaxPrice}"  name="mx[noTaxPrice][]" onblur="getMoneys(this)"></td>
                        <td><input type="text" class="layui-input bjMoney" value="{$mxl.bjMoney}" readonly name="mx[bjMoney][]"></td>
                        <td><input type="text" class="layui-input" name="mx[remark][]" value="{$mxl.remark}"></td>
                        <td><input type="text" name="mx[saleContractOrderNum][]" class="layui-input" value="{$mxl.saleContractOrderNum}" readonly></td>
                        <td>{$mxl.saleNum}</td>
                        <td>{$mxl.unBuyNum}</td>
                        <td>{$mxl.bjTime}</td>
                        <td>
<!--                            {if !isset($detail.status)||$detail.status==1}-->
<!--                            <a href="javascript:" class="layui-btn layui-btn-xs layui-btn-danger"-->
<!--                               onclick="delMx('{$mxl.id}',this)">删除</a>-->
<!--                            {/if}-->
                        </td>
                    </tr>
                    {/volist}
                    {/if}
                    </tbody>
                </table>

            </td>
        </tr>
        <tr>
            <td colspan="17">
                <div class="countBan">
                    <div class="count_item_show">数量合计：<span id="numCount">{$countNum|default=0}</span></div>
                    <div class="count_item_show">金额合计：<span id="priceCount">{$countPrice|default=0}</span></div>
                </div>
            </td>
        </tr>
        <tr>

            <td class="layui-td-gray">附件
            </td>
            <td>
                <div style="display: flex">
                    <input type="hidden" name="fjs" id="fjs" data-canDo="0" value="{$detail.fjs|default=''}"
                           autocomplete="off" placeholder="请输入"
                           class="layui-input">
                </div>

            </td>

        </tr>
    </table>




</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool','employeepicker','oaTool'];
    let contactList=[];
    let saveList=[];
    let punterId="{$detail.punterId|default=''}"
    let salesUnitId="{$detail.salesUnitId|default=''}"
    function gouguInit() {
        var form = layui.form, tool = layui.tool, level = 0,oaTool = layui.oaTool, laydate = layui.laydate;
        //监听提交
        form.on('submit(webform)', function (data) {
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    setTimeout(function () {
                        parent.parent.location.reload();
                    }, 1000);
                }
            }
            tool.post("{:url('add')}", data.field, callback);
            return false;
        });
        laydate.render({
            elem: '.mxBjTime',// 指定元素
            type: 'date',
        });

        $("#mxPl").click(function () {
            layer.open({
                type: 1,
                title: '销售合同货期',
                area: ['500px', '200px'],
                btn: ['确定'],
                content: '<form class="layui-form" id="printForm" action="">' +
                    '  <div class="layui-form-item" >' +
                    '    <label class="layui-form-label" style="margin: 0;width: 90px">选择时间</label>' +
                    '    <div class="layui-input-block">' +
                    '      <input type="text " style="width: 200px" class="layui-input" id="pl_bjTime" readonly name="pl_bjTime" title="选择时间">' +
                    '    </div>' +
                    '  </div>' +
                    '</form>',
                success: function (layero, index) {
                    // 渲染表单
                    layui.laydate.render({
                        elem: "#pl_bjTime"
                    })
                    form.render();
                    //
                    // // 监听提交事件
                    // form.on('radio(printType)', function(data){
                    //     console.log(data.value); // 获取选中的值
                    //     layer.close(index); // 关闭弹窗
                    // });
                },
                yes: function (index) {
                    var form = document.getElementById('printForm');
                    let times = $("#pl_bjTime").val()
                    $('.tableMany tr').find('.mxBjTime').val(times);
                    layer.close(index);
                }
            });
        })

        form.on('select(punterId)', function (data) {
            console.log('data',data)
            getPunterMember(data.value);
        });
        form.on('select(salesUnitId)', function (data) {
            let val=data.value;
            getDepartUser(val);
        });

        form.on('select(contactId)', function (data) {
            let value=data.value;
            if (data.value==''){
                $("input[name ='contactName']").val();
                $("input[name ='contactPhone']").val();
            }else {
                contactList.forEach(function (item) {
                    if (item.id==value){
                        $("input[name ='contactName']").val(item.name);
                        $("input[name ='contactPhone']").val(item.phone);
                        return;
                    }
                })
            }
        });
        form.on('select(saveId)', function (data) {
            let value=data.value;
            if (data.value==''){
                $("input[name ='saveName']").val();
                $("input[name ='savePhone']").val();
                $("input[name ='saveAdd']").val();
            }else {
                saveList.forEach(function (item) {
                    if (item.id==value){
                        $("input[name ='saveName']").val(item.name);
                        $("input[name ='savePhone']").val(item.phone);
                        $("input[name ='saveAdd']").val(item.address);
                        return;
                    }
                })
            }
        });
        laydate.render({
            elem:"#orderDate"
        })
        $(document).on('click', '.mxBjTime', function(){
            laydate.render({
                elem: this // 绑定当前点击的元素
            });
        });

        getPunterMember(punterId);
        getDepartUser(salesUnitId)

        form.on('select(flowtype)', function(data){
            var check_type = data.elem[data.elem.selectedIndex].title;
            var formHtml='<td class="layui-td-gray">审核人<font>*</font></td>\
			<td colspan="5">\
				<input type="text" name="check_admin_name" value="" autocomplete="off" placeholder="请选择审核人" lay-verify="required" lay-reqText="请选择审核人" class="layui-input picker-one"><input type="hidden" name="check_admin_ids" value="">\
			</td>';
            if(check_type == 2){
                $('#flow_tr').html(formHtml);
                form.render();
            }
            if(data.value==''){
                return false;
            }
            console.log('checkType',check_type)
            $.ajax({
                url: "/api/index/get_flow_users",
                type:'get',
                data:{id:data.value},
                success: function (e) {
                    if (e.code == 0) {
                        var flowLi='';
                        var flow_data = e.data.flow_data;
                        if(e.data.copy_uids && e.data.copy_uids !=''){
                            $('[name="copy_names"]').val(e.data.copy_unames);
                            $('[name="copy_uids"]').val(e.data.copy_uids.split(','));
                        }
                        if(check_type == 1 || check_type == 3){
                            for(var a=0;a<flow_data.length;a++){
                                var userList='',sign_type = '';
                                if(check_type == 1){
                                    if(flow_data[a].flow_type==1){
                                        userList+= '<li style="padding:3px 0">当前部门负责人</li>';
                                    }
                                    else if(flow_data[a].flow_type==2){
                                        userList+= '<li style="padding:3px 0">上级部门负责人</li>';
                                    }
                                    else{
                                        if(flow_data[a].flow_type==3){
                                            sign_type= ' <span class="layui-badge layui-bg-blue">或签</span>';
                                        }
                                        if(flow_data[a].flow_type==4){
                                            sign_type= ' <span class="layui-badge layui-bg-blue">会签</span>';
                                        }
                                        for(var b=0;b<flow_data[a].user_id_info.length;b++){
                                            userList+= '<li style="padding:3px 0"><img src="'+flow_data[a].user_id_info[b].thumb+'" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />'+flow_data[a].user_id_info[b].name+'</li>';
                                        }
                                    }
                                }
                                else if(check_type == 3){
                                    sign_type= ' <span class="layui-badge layui-bg-blue">'+flow_data[a].flow_name+'</span>'
                                    for(var b=0;b<flow_data[a].user_id_info.length;b++){
                                        userList+= '<li style="padding:3px 0"><img src="'+flow_data[a].user_id_info[b].thumb+'" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />'+flow_data[a].user_id_info[b].name+'</li>';
                                    }
                                }
                                flowLi+='<li class="layui-timeline-item">\
									<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
									<div class="layui-timeline-content">\
									  <p class="layui-timeline-title"><strong>第'+(a+1)+'级审批</strong>'+sign_type+'</p>\
									  <ul>'+userList+'</ul>\
									</div>\
								</li>';
                            }
                            formHtml = '<td class="layui-td-gray">审批流程</td>\
										<td colspan="7">\
											<ul id="flowList" class="layui-timeline">'+flowLi+'</ul>\
										</td>';
                            $('#flow_tr').html(formHtml);
                        }
                    }
                }
            })
        });


        $('#formBtn').on('click','span', function(data){
            let id=$('[name="id"]').val();
            let content=$('[name="content"]').val();
            let check_status=$(this).data('status');
            let status=4;
            let flow_type = $('input[name="flow_type"]').val();
            let check_node=0,check_admin_ids=0;
            if(flow_type == 0 && check_status==1){
                check_node = $('input[name="check_node"]:checked').val();
                check_admin_ids = $('input[name="check_admin_ids"]').val();
                if(!check_node){
                    layer.msg('请选择下一审批节点');
                    return false;
                }
                if(check_node == 2 && check_admin_ids==''){
                    layer.msg('请选择下一审批人');
                    return false;
                }
            }
            if(check_status ==1 || check_status==2){
                if(content==''){
                    layer.msg('请输入审批意见');
                    return false;
                }
                let confirmTips='确定通过该审核？';
                if(check_status==2){
                    confirmTips='确定拒绝该审核？';
                    status=5;

                }
                layer.confirm(confirmTips, function(index){
                    $.ajax({
                        url: "/api/index/flow_check",
                        type:'post',
                        data:{
                            id:id,
                            type:4,
                            check_node:check_node,
                            check_admin_ids:check_admin_ids,
                            check:check_status,
                            content:content
                        },
                        success: function (e) {
                            layer.msg(e.msg);
                            if (e.code == 0) {
                                tool.sideClose(1000);
                            }
                        }
                    })
                    layer.close(index);
                });
            }
            else if(check_status == 3){
                layer.prompt({
                    formType: 2,
                    title: '请输入撤回理由',
                    area: ['500px', '120px'] //自定义文本域宽高
                }, function(value, index, elem){
                    if(value==''){
                        layer.msg('请输入撤回理由');
                        return false;
                    }
                    $.ajax({
                        url: "/api/index/flow_check",
                        type:'post',
                        data:{
                            id:id,
                            type:4,
                            check:check_status,
                            content:value
                        },
                        success: function (e) {
                            layer.msg(e.msg);
                            if (e.code == 0) {
                                tool.sideClose(1000);
                            }
                        }
                    })
                    layer.close(index);
                });
            }
            return false;
        });
        uploadFiles("#fjs")
    }

    let mxIndex = '';

    function saveAddMx(ojb) {
        var lastListItem = $('.tableMany tr:last');
        let aa = $(lastListItem).find(".xuhao")
        layer.close(mxIndex)
        console.log('aaa', ojb)
        let len = $(aa).text()
        if (!parseInt(len)) {
            len = 0;
        }
        let index = parseInt(len) + 1;
        let str = '';
        for (var i = 0; i < ojb.length; i++) {
            let item = ojb[i];
            let saleContractDetailId=item.id||0;
            let saleContractOrderNum=item.orderNum||'';
            str += '      <tr>\n' +
                '                        <td>\n' +
                '                            <span class="xuhao">' + index + '</span>\n' +
                '                            <input type="hidden" name="mx[mxid][]" value="">\n' +
                '                            <input type="hidden" class="noTaxMoney" name="mx[noTaxMoney][]" value="">\n' +
                '                            <input type="hidden" class="taxMoney" name="mx[taxMoney][]" value="">\n' +
                '                            <input type="hidden" class="mx_saleContractDetailId" name="mx[saleContractDetailId][]" value="'+saleContractDetailId+'">\n' +
                '                            <input type="hidden" class="mx_mdId" name="mx[mdId][]" value="' + item.mdId + '">\n' +
                '                        </td>\n' +
                // '                        <td>' + item.bar_code + '</td>\n' +
                '                        <td>' + item.brand + '</td>\n' +
                '                        <td>' + item.mdName + '</td>\n' +
                '                        <td>' + item.specs + '</td>\n' +
                '                        <td>' + item.buyCode + '</td>\n' +
                '                        <td>' + item.unit + '</td>\n' +
                '                        <td><input type="text" name="mx[bjNum][]" value="'+item.unBuyNum+'" class="layui-input bjNum" onblur="getMoneys(this)" lay-verify="required" oninput="digitalFiltering(this,4)"></td>\n' +
                '                        <td><input type="text" name="mx[bjPrice][]" class="layui-input bjPrice" onblur="getMoneys(this)" lay-verify="required" oninput="digitalFiltering(this,4)"></td>\n' +
                '                        <td> <input type="text" class="layui-input noTaxPrice"  name="mx[noTaxPrice][]" onblur="getMoneys(this)"></td>\n' +
                '                        <td>  <input type="text" class="layui-input bjMoney" readonly name="mx[bjMoney][]"></td>\n' +
                // '                        <td>  <input type="text" class="layui-input noTaxMoney" readonly name="mx[noTaxMoney][]"></td>\n' +
                // '                        <td>  <input type="text" class="layui-input taxMoney" readonly name="mx[taxMoney][]"></td>\n' +
                // '                        <td><input type="text" name="mx[bjTime][]" class="layui-input mxBjTime" readonly lay-verify="required" placeholder="选择时间"></td>\n' +
                // '                        <td><input type="text" class="layui-input"  name="mx[proCode][]" lay-verify="required"></td>\n' +
                '                        <td><input type="text" class="layui-input" name="mx[remark][]"></td>\n' +
                '                        <td><input type="text" name="mx[saleContractOrderNum][]" class="layui-input" value="'+saleContractOrderNum+'" readonly></td>\n' +
                '                        <td>'+item.saleNum+'</td>\n' +
                '                        <td>'+item.unBuyNum+'</td>\n' +
                '                        <td><a href="javascript:" class="layui-btn layui-btn-xs layui-btn-danger" onclick="delMx(\'\',this)">删除</a></td>\n' +
                '                    </tr>';
            index++;
        }
        $("#mxTbdy").append(str)
        layui.form.render();
    }

    function delMx(id = '', e) {
        if (id == '') {
            $(e).parent().parent().remove()
            return;
        }
        $.ajax({
            url: "{:url('removeMx')}",
            type: 'post',
            dataType: 'json',
            data: {id: id},
            success: function (res) {
                if (res.code != 0) {
                    layer.msg(res.msg)
                } else {
                    $(e).parent().parent().remove()
                }
            },
            error(e) {
                layer.msg('网络错误，请稍后')
            }
        })
    }

    function getMoneys(ojb) {
        let tax = $("#tax").val()
        if (!parseInt(tax)) {
            tax = 0;
        } else {
            tax = parseFloat(tax / 100)
        }
        console.log('tax',tax)
        let trObj = $(ojb).parent().parent();
        let bjNum = trObj.find(".bjNum").val()
        let bjPrice = trObj.find(".bjPrice").val()
        if (bjPrice==''){
            bjPrice==0;
        }
        let noTaxPrice = trObj.find(".noTaxPrice").val()
        if (noTaxPrice==''){
            noTaxPrice=0;
        }
        let noTaxMoney = 0;
        let taxMoney = 0;
        let bjMoney = 0;
        if ($(ojb).hasClass('noTaxPrice')){
            noTaxPrice=parseFloat(noTaxPrice);
            bjPrice=noTaxPrice*(1+tax)
            trObj.find(".bjPrice").val(bjPrice.toFixed(4))
        }else if ($(ojb).hasClass('bjPrice')){
            noTaxPrice= parseFloat(bjPrice/(1+tax))
        }else {
            noTaxPrice= parseFloat(noTaxPrice)
        }

        bjMoney=parseFloat(bjNum*bjPrice)
        noTaxMoney=parseFloat(bjNum*noTaxPrice);
        taxMoney= parseFloat( Math.abs(bjMoney-noTaxMoney))
        console.log('taxMoney',taxMoney)
        console.log('nottaxMoney',noTaxMoney)
        trObj.find(".noTaxPrice").val(noTaxPrice.toFixed(4))
        trObj.find(".bjMoney").val(bjMoney.toFixed(4))
        trObj.find(".noTaxMoney").val(noTaxMoney.toFixed(4))
        trObj.find(".taxMoney").val(taxMoney.toFixed(4))
    }

    function getPunterMember(punterId='') {
        $("#contactId").empty();
        $("#saveId").empty();
        $("input[name ='contactName']").val();
        $("input[name ='contactPhone']").val();
        $("input[name ='saveName']").val();
        $("input[name ='savePhone']").val();
        $("input[name ='saveAdd']").val();
        contactList=[];
        saveList=[];
        if (punterId==''){
            layui.form.render();
            return;
        }
        httpRequest("{:url('api/getPurveyorMember')}",{purveyorId:punterId},function (res) {
            if (res.code==0){
                contactList=res.data.contactList;
                saveList=res.data.saverList;
                let contactStr='  <option value="">请选择</option>';
                let saverStr='  <option value="">请选择</option>';
                let contactId="{$detail.contactId|default='0'}"
                let saveId="{$detail.saveId|default='0'}"
                contactList.forEach(function (item) {
                    let cStr='';
                    if (item.id==contactId){
                        cStr='selected';
                    }
                    contactStr+='  <option value="'+item.id+'" '+cStr+'>'+item.name+'</option>'
                })
                saveList.forEach(function (item) {
                    let s_Str='';
                    if (item.id==saveId){
                        s_Str='selected';
                    }
                    saverStr+='  <option value="'+item.id+'" '+s_Str+'>'+item.name+'</option>'
                })
                console.log(saverStr)
                $("#contactId").append(contactStr);
                $("#saveId").append(saverStr);
                layui.form.render();
            }else {

            }
        },false)
    }

    function getDepartUser(departId='') {
        $("#saleId").empty();
        if (departId==''){
            layui.form.render();
            return;
        }
        httpRequest("{:url('api/getDepartUser')}",{did:departId},function (res) {
            if (res.code==0){
                let data=res.data;
                let saleStr='';
                let saleId="{$detail.saleId|default='0'}"
                data.forEach(function (item) {
                    let sstr='';
                    if (item.id==saleId){
                        sstr='selected';
                    }
                    saleStr+=' <option value="'+item.id+'" '+sstr+'>'+item.name+'</option>';
                })

                $("#saleId").append(saleStr);
                layui.form.render();
            }
        },false)
    }

    function getBjd() {
        // let khId=$("#punterId").val();
        // if (khId==''){
        //     layer.msg('请选择供应商');
        //     return
        // }
        let mxId=[];
        let inputs=document.getElementsByClassName('mx_saleContractDetailId');
        for (var i = 0; i < inputs.length; i++) {
            // 确保只获取文本或数字类型的输入框值
            mxId.push(inputs[i].value);
        }
        // boxModel("{:url('addMx')}?khId="+khId,'关联报价单','1000')
        boxModel("{:url('addMx')}?mxId="+mxId.join(','),'关联销售合同','1000')
    }

    function getPro() {
        let mdId=[];
        let inputs=document.getElementsByClassName('mx_mdId');
        for (var i = 0; i < inputs.length; i++) {
            // 确保只获取文本或数字类型的输入框值
            mdId.push(inputs[i].value);
        }
        // boxModel("{:url('addMx')}?khId="+khId,'关联报价单','1000')
        boxModel("{:url('addPro')}?mdId="+mdId.join(','),'选择产品','1000')
    }

    function onSure() {
        httpRequest("{:url('onSure')}",{id:"{$id}"},function (res) {
            if (res.code==0){
                parent.parent.location.reload();
            }
        })
    }
    function onSub() {
        httpRequest("{:url('onSub')}",{id:"{$id}"},function (res) {
            if (res.code==0){
                parent.parent.location.reload();
            }
        })
    }
    function onChick(type=1) {
        httpRequest("{:url('onChick')}",{id:"{$id}",type:type},function (res) {
            if (res.code==0){
                parent.parent.location.reload();
            }
        })
    }

    function onCancel() {
        httpRequest("{:url('onCancel')}",{id:"{$id}"},function (res) {
            if (res.code==0){
                parent.parent.location.reload();
            }
        })
    }
</script>
{/block}
<!-- /脚本 -->